package com.bto.solar.work.common;


import com.bto.solar.work.constant.BizCode;
import com.bto.solar.work.utils.StringUtils;
import lombok.extern.slf4j.Slf4j;

/**
 * @author wxb
 * @description:业务异常
 * @date 2023/3/15 9:49
 */

@Slf4j
public class BizException extends RuntimeException{


    /**
    *通用业务异常
    */
    private final Integer code;
    /**
    *异常信息
    */
    private final String errMsg;

    public BizException(){
        super(BizCode.BizCommonExceptionCode.getMsg());
        this.code = BizCode.BizCommonExceptionCode.getCode();
        this.errMsg = BizCode.BizCommonExceptionCode.getMsg();
    }

    public BizException(BizCode exceptionCode){
        super(exceptionCode.getMsg());
        this.code = exceptionCode.getCode();
        this.errMsg = exceptionCode.getMsg();
    }

    public BizException(Integer code , String errMsg){
        super(errMsg);
        this.code = code;
        this.errMsg = errMsg;
    }

     public BizException(String errMsg){
        super(errMsg);
        this.code = BizCode.BizCommonExceptionCode.getCode();
        this.errMsg = errMsg;
    }

    public BizException(String format  , Object... arguments){
        super(StringUtils.format(format  , arguments));
        String errMsg = StringUtils.format(format  , arguments);
        this.code = BizCode.BizCommonExceptionCode.getCode();
        this.errMsg = errMsg;
    }

    public Integer getCode() {
        return code;
    }

    public String getErrMsg() {
        return errMsg;
    }

    /**
     * 不写入堆栈信息，提高性能
     */
    @Override
    public Throwable fillInStackTrace() {
        return this;
    }



}
